home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GetCodecInfoApp.c
-
- Contains: Code for develop column .
-
- Written by: John Wang
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <1> 11/01/94 JW New.
-
- To Do:
-
- */
-
- #ifdef THINK_C
- #define applec
- #endif
-
- #include "SpinCursor.h"
- #include "GetCodecInfoApp.h"
-
- #ifdef powerc
- QDGlobals qd;
- #endif
-
- short gRefNum;
- PicHandle gPicture;
-
- void main(void)
- {
- OSErr err;
- long vers;
- StandardFileReply myReply;
-
- // Create a heap with lots of master pointers.
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters(); MoreMasters();
-
- // Initialize managers.
- InitGraf(&qd.thePort);
- FlushEvents(everyEvent, 0);
- InitWindows();
- InitDialogs(nil);
- InitCursor();
-
- // Require at least System 7.0 and Quicktime.
- Gestalt(gestaltSystemVersion, &vers);
- vers = (vers >> 8) & 0x0f;
- if ( vers < 7 ) {
- ReportWarning("\pThis Application requires System 7 or later!");
- ExitToShell();
- }
- err = Gestalt(gestaltQuickTime, &vers);
- if ( err != noErr ) {
- ReportWarning("\pQuickTime is required. Please install it and try again.");
- ExitToShell();
- }
- err = EnterMovies();
- if ( err != noErr ) {
- ReportWarning("\pQuickTime is required. Please install it and try again.");
- ExitToShell();
- }
-
- // Initialize.
- err = noErr;
- gRefNum = -1;
- gPicture = (PicHandle) NewHandle(4);
- if ( gPicture != nil ) {
- PicHandle tempPicture;
-
- tempPicture = GetPicture(128);
- if ( tempPicture != nil ) {
- err = CompressPicture(tempPicture, gPicture, codecHighQuality, 0);
- if ( err != noErr ) {
- ReportWarning("\pCould not create picture for testing codec speed. (Not enough memory).");
- DisposeHandle((Handle) gPicture);
- gPicture = nil;
- }
- DisposeHandle((Handle) tempPicture);
- } else {
- ReportWarning("\pCould not find picture in resource id #128 for testing codec speed.");
- DisposeHandle((Handle) gPicture);
- gPicture = nil;
- }
- }
-
- // Get file.
- StandardPutFile("\pFile to save report to:", "\pCodecInfo Report", &myReply);
- if (!(myReply.sfGood))
- goto end;
-
- // Create file.
- err = FSpCreate(&(myReply.sfFile), 'ttxt', 'TEXT', smSystemScript);
- if ( err != noErr ) {
- FSpDelete(&(myReply.sfFile));
- err = FSpCreate(&(myReply.sfFile), 'ttxt', 'TEXT', smSystemScript);
- if ( err != noErr ) {
- ReportWarning("\pCouldn't create file.");
- goto end;
- }
- }
-
- // Open output file
- err = FSpOpenDF(&(myReply.sfFile), fsWrPerm, &gRefNum);
- if ( err != noErr ) {
- gRefNum = -1;
- ReportWarning("\pCouldn't open file.");
- goto end;
- }
-
- // Set beginning position
- err = SetFPos(gRefNum, fsFromStart, 0);
- if ( err != noErr ) {
- ReportWarning("\pCouldn't set to beginning of file.");
- goto end;
- }
-
- // Write something
- ReportHeader();
- ReportCodecList();
-
- // Finish up.
- end:
- if ( gRefNum != -1 )
- FSClose(gRefNum);
-
- ExitToShell();
- }
-
- /* ------------------------------------------------------------------------- */
-
- void ReportWarning(Str255 theStr)
- {
- short itemHit;
- DialogPtr myDialog;
-
- ParamText("\pWARNING!", theStr, nil, nil);
- myDialog = GetNewDialog(kDLOG_ERROR, 0, (WindowPtr) -1);
- do {
- ModalDialog(nil, &itemHit);
- } while ( (itemHit != ok) );
- DisposeDialog(myDialog);
- }
-
- /* ------------------------------------------------------------------------- */
-
- void WriteStr(Str255 str)
- {
- long count;
-
- count = str[0];
- FSWrite(gRefNum, &count, (unsigned char *) &str[1]);
- }
-
- void WriteBuf(unsigned char *str, long count)
- {
- FSWrite(gRefNum, &count, (unsigned char *) str);
- }
-
- void WriteReturn(void)
- {
- long count;
-
- count = 1;
- FSWrite(gRefNum, &count, (unsigned char *) "\r");
- }
-
- void WriteResourceStr(short id)
- {
- Handle str;
- long count;
- char state;
-
- str = Get1Resource('TEXT', id);
- count = GetHandleSize(str);
-
- state = HGetState(str);
- HLock(str);
- FSWrite(gRefNum, &count, (unsigned char *) *str);
- HSetState(str, state);
- }
-
- /* ------------------------------------------------------------------------- */
-
- void ReportHeader(void)
- {
- WriteResourceStr(kSTR_INTRO);
- WriteResourceStr(kSTR_COMPRESS);
- WriteResourceStr(kSTR_DECOMPRESS);
- }
-
- void ReportCodecList(void)
- {
- OSErr err;
- ComponentDescription desc, foundComp;
- Component comp;
- ComponentInstance compinst;
- CodecInfo info;
- short i;
-
-
- // Find compressors.
- desc.componentType = compressorComponentType;
- desc.componentSubType = 0;
- desc.componentManufacturer = 0;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
- comp = 0;
-
- do {
- comp = FindNextComponent(comp, &desc);
- if ( comp != nil ) {
- GetComponentInfo(comp, &foundComp, nil, nil, nil);
- compinst = OpenComponent(comp);
- if ( compinst != 0 ) {
- CallGetCodecInfo(compinst, &info);
- ReportCompressor(&info);
- ReportCompressorSpeed(foundComp.componentSubType);
- WriteReturn();
- CloseComponent(compinst);
- }
- }
- } while ( comp != nil );
-
- WriteReturn();
-
- // Find compressors.
- desc.componentType = decompressorComponentType;
- desc.componentSubType = 0;
- desc.componentManufacturer = 0;
- desc.componentFlags = 0;
- desc.componentFlagsMask = 0;
- comp = 0;
-
- do {
- comp = FindNextComponent(comp, &desc);
- if ( comp != nil ) {
- GetComponentInfo(comp, &foundComp, nil, nil, nil);
- compinst = OpenComponent(comp);
- if ( compinst != 0 ) {
- CallGetCodecInfo(compinst, &info);
- ReportDecompressor(&info);
- ReportDecompressorSpeed(foundComp.componentSubType);
- WriteReturn();
- CloseComponent(compinst);
- }
- }
- } while ( comp != nil );
- }
-
- void ReportCompressor(CodecInfo *info)
- {
- Str255 str;
-
- WriteStr("\pCompressor Name: ");
- WriteStr(info->typeName);
- WriteStr("\p\r------------------------------------\r");
-
- WriteStr("\p - version = ");
- NumToString((long) info->version, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - revisionLevel = ");
- NumToString((long) info->revisionLevel, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - vendor = ");
- WriteBuf((unsigned char *) &(info->vendor), 4);
- WriteReturn();
-
- WriteStr("\p - compressionAccuracy = ");
- NumToString((long) info->compressionAccuracy, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - compressionSpeed = ");
- NumToString((long) info->compressionSpeed, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - compressionLevel = ");
- NumToString((long) info->compressionLevel, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - minimum height = ");
- NumToString((long) info->minimumHeight, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - minimum width = ");
- NumToString((long) info->minimumWidth, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - compress pipeline latency = ");
- NumToString((long) info->compressPipelineLatency, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - compression capabilities:\r");
- if ( info->compressFlags & codecInfoDoes1 )
- WriteStr("\p directly compresses 1-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes2 )
- WriteStr("\p directly compresses 2-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes4 )
- WriteStr("\p directly compresses 4-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes8 )
- WriteStr("\p directly compresses 8-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes16 )
- WriteStr("\p directly compresses 16-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes32 )
- WriteStr("\p directly compresses 32-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoesDither )
- WriteStr("\p supports fast dithering\r");
- if ( info->compressFlags & codecInfoDoesStretch )
- WriteStr("\p can stretch to arbitrary sizes in codec\r");
- if ( info->compressFlags & codecInfoDoesShrink )
- WriteStr("\p can shrink to arbitrary sizes in codec\r");
- if ( info->compressFlags & codecInfoDoesMask )
- WriteStr("\p supports clipping regions\r");
- if ( info->compressFlags & codecInfoDoesTemporal )
- WriteStr("\p supports temporal compression\r");
- if ( info->compressFlags & codecInfoDoesDouble )
- WriteStr("\p can stretch to double size\r");
- if ( info->compressFlags & codecInfoDoesQuad )
- WriteStr("\p can stretch to quad size\r");
- if ( info->compressFlags & codecInfoDoesHalf )
- WriteStr("\p can shrink to half size\r");
- if ( info->compressFlags & codecInfoDoesQuarter )
- WriteStr("\p can shrink to quarter size\r");
- if ( info->compressFlags & codecInfoDoesRotate )
- WriteStr("\p can rotate\r");
- if ( info->compressFlags & codecInfoDoesHorizFlip )
- WriteStr("\p can flip horizontally\r");
- if ( info->compressFlags & codecInfoDoesVertFlip )
- WriteStr("\p can flip vertically\r");
- if ( info->compressFlags & codecInfoDoesSkew )
- WriteStr("\p can skew image\r");
- if ( info->compressFlags & codecInfoDoesBlend )
- WriteStr("\p can blend image with matte\r");
- if ( info->compressFlags & codecInfoDoesWarp )
- WriteStr("\p can warp image arbitrarily\r");
- if ( info->compressFlags & codecInfoDoesRecompress )
- WriteStr("\p can recompresses images without accumulating errors\r");
- if ( info->compressFlags & codecInfoDoesSpool )
- WriteStr("\p can use data-loading or unloading function\r");
- if ( info->compressFlags & codecInfoDoesRateConstrain )
- WriteStr("\p can rate constrain to caller defined limit\r");
-
- WriteStr("\p - compression format:\r");
- if ( info->formatFlags & codecInfoDepth1 )
- WriteStr("\p can store images in 1-bit color\r");
- if ( info->formatFlags & codecInfoDepth2 )
- WriteStr("\p can store images in 2-bit color\r");
- if ( info->formatFlags & codecInfoDepth4 )
- WriteStr("\p can store images in 4-bit color\r");
- if ( info->formatFlags & codecInfoDepth8 )
- WriteStr("\p can store images in 8-bit color\r");
- if ( info->formatFlags & codecInfoDepth16 )
- WriteStr("\p can store images in 16-bit color\r");
- if ( info->formatFlags & codecInfoDepth24 )
- WriteStr("\p can store images in 24-bit color\r");
- if ( info->formatFlags & codecInfoDepth32 )
- WriteStr("\p can store images in 32-bit color\r");
- if ( info->formatFlags & codecInfoDepth33 )
- WriteStr("\p can store images in 1-bit monochrome\r");
- if ( info->formatFlags & codecInfoDepth34 )
- WriteStr("\p can store images in 2-bit grayscale\r");
- if ( info->formatFlags & codecInfoDepth36 )
- WriteStr("\p can store images in 4-bit grayscale\r");
- if ( info->formatFlags & codecInfoDepth40 )
- WriteStr("\p can store images in 8-bit grayscale\r");
- if ( info->formatFlags & codecInfoStoresClut )
- WriteStr("\p can store custom color table\r");
- if ( info->formatFlags & codecInfoDoesLossless )
- WriteStr("\p can store in lossless format\r");
- if ( info->formatFlags & codecInfoSequenceSensitive ) {
- WriteStr("\p compressed data requires non-key frames to be decompressed\r");
- WriteStr("\p in same order as compressed\r");
- }
- }
-
- void ReportDecompressor(CodecInfo *info)
- {
- Str255 str;
-
- WriteStr("\pDecompressor Name: ");
- WriteStr(info->typeName);
- WriteStr("\p\r------------------------------------\r");
-
- WriteStr("\p - version = ");
- NumToString((long) info->version, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - revisionLevel = ");
- NumToString((long) info->revisionLevel, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - vendor = ");
- WriteBuf((unsigned char *) &(info->vendor), 4);
- WriteReturn();
-
- WriteStr("\p - decompressionAccuracy = ");
- NumToString((long) info->decompressionAccuracy, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - decompressionSpeed = ");
- NumToString((long) info->decompressionSpeed, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - minimum height = ");
- NumToString((long) info->minimumHeight, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - minimum width = ");
- NumToString((long) info->minimumWidth, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - decompress pipeline latency = ");
- NumToString((long) info->decompressPipelineLatency, str);
- WriteStr(str);
- WriteReturn();
-
- WriteStr("\p - decompression capabilities:\r");
- if ( info->compressFlags & codecInfoDoes1 )
- WriteStr("\p directly decompresses into 1-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes2 )
- WriteStr("\p directly decompresses into 2-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes4 )
- WriteStr("\p directly decompresses into 4-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes8 )
- WriteStr("\p directly decompresses into 8-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes16 )
- WriteStr("\p directly decompresses into 16-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoes32 )
- WriteStr("\p directly decompresses into 32-bit pixels maps\r");
- if ( info->compressFlags & codecInfoDoesDither )
- WriteStr("\p supports fast dithering\r");
- if ( info->compressFlags & codecInfoDoesStretch )
- WriteStr("\p can stretch to arbitrary sizes in codec\r");
- if ( info->compressFlags & codecInfoDoesShrink )
- WriteStr("\p can shrink to arbitrary sizes in codec\r");
- if ( info->compressFlags & codecInfoDoesMask )
- WriteStr("\p supports clipping regions\r");
- if ( info->compressFlags & codecInfoDoesTemporal )
- WriteStr("\p supports temporal compression\r");
- if ( info->compressFlags & codecInfoDoesDouble )
- WriteStr("\p can stretch to double size\r");
- if ( info->compressFlags & codecInfoDoesQuad )
- WriteStr("\p can stretch to quad size\r");
- if ( info->compressFlags & codecInfoDoesHalf )
- WriteStr("\p can shrink to half size\r");
- if ( info->compressFlags & codecInfoDoesQuarter )
- WriteStr("\p can shrink to quarter size\r");
- if ( info->compressFlags & codecInfoDoesRotate )
- WriteStr("\p can rotate\r");
- if ( info->compressFlags & codecInfoDoesHorizFlip )
- WriteStr("\p can flip horizontally\r");
- if ( info->compressFlags & codecInfoDoesVertFlip )
- WriteStr("\p can flip vertically\r");
- if ( info->compressFlags & codecInfoDoesSkew )
- WriteStr("\p can skew image\r");
- if ( info->compressFlags & codecInfoDoesBlend )
- WriteStr("\p can blend image with matte\r");
- if ( info->compressFlags & codecInfoDoesWarp )
- WriteStr("\p can warp image arbitrarily\r");
- if ( info->compressFlags & codecInfoDoesRecompress )
- WriteStr("\p can recompress images without accumulating errors\r");
- if ( info->compressFlags & codecInfoDoesSpool )
- WriteStr("\p can use data-loading or unloading function\r");
- if ( info->compressFlags & codecInfoDoesRateConstrain )
- WriteStr("\p can rate contrain to caller defined limit\r");
-
- WriteStr("\p - decompression format:\r");
- if ( info->formatFlags & codecInfoDepth1 )
- WriteStr("\p can decompress images from 1-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth2 )
- WriteStr("\p can decompress images from 2-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth4 )
- WriteStr("\p can decompress images from 4-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth8 )
- WriteStr("\p can decompress images from 8-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth16 )
- WriteStr("\p can decompress images from 16-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth24 )
- WriteStr("\p can decompress images from 24-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth32 )
- WriteStr("\p can decompress images from 32-bit color compressed format\r");
- if ( info->formatFlags & codecInfoDepth33 )
- WriteStr("\p can decompress images from 1-bit monochrome compressed format\r");
- if ( info->formatFlags & codecInfoDepth34 )
- WriteStr("\p can decompress images from 2-bit grayscale compressed format\r");
- if ( info->formatFlags & codecInfoDepth36 )
- WriteStr("\p can decompress images from 4-bit grayscale compressed format\r");
- if ( info->formatFlags & codecInfoDepth40 )
- WriteStr("\p can decompress images from 8-bit grayscale compressed format\r");
- if ( info->formatFlags & codecInfoStoresClut )
- WriteStr("\p can store custom color table\r");
- if ( info->formatFlags & codecInfoDoesLossless )
- WriteStr("\p can store in lossless format\r");
- if ( info->formatFlags & codecInfoSequenceSensitive ) {
- WriteStr("\p compressed data requires non-key frames to be decompressed\r");
- WriteStr("\p in same order as compressed\r");
- }
- }
-
- void ReportCompressorSpeed(OSType type)
- {
- OSErr err;
- Str255 str;
- PicHandle tempPicture;
- long begin, end, times;
- Boolean failed;
- GWorldPtr gworld;
- CGrafPtr saveport;
- GDHandle savegdevice;
- Rect myRect = {0, 0, 480, 640};
- Boolean animCur;
-
- // Initialize.
- gworld = nil;
-
- if ( gPicture == nil )
- return;
-
- animCur = InitAnimatedCursors(beachBall, 0);
-
- if ( animCur )
- SpinCursor();
-
- failed = false;
- GetGWorld(&saveport, &savegdevice);
- err = NewGWorld(&gworld, 32, &myRect, nil, nil, 0);
- if ( err == noErr ) {
- PixMapHandle pmap;
- ImageDescriptionHandle desc;
- long size;
- Ptr data;
-
- if ( animCur )
- SpinCursor();
- SetGWorld(gworld, nil);
- LockPixels(GetGWorldPixMap(gworld));
- pmap = GetGWorldPixMap(gworld);
- EraseRect(&myRect);
- DrawPicture(gPicture, &myRect);
- desc = (ImageDescriptionHandle) NewHandle(4);
- if ( desc != nil ) {
- err = GetMaxCompressionSize(pmap, &myRect, 32, codecHighQuality, type, anyCodec, &size);
- if ( err == noErr ) {
- begin = TickCount();
- for ( times = 10; times > 0; times-- ) {
- data = NewPtr(size);
- if ( data != nil ) {
- err = CompressImage(pmap, &myRect, codecHighQuality, type, desc, data);
- if ( err != noErr )
- failed = true;
- if ( animCur )
- SpinCursor();
- DisposePtr(data);
- } else
- failed = true;
- }
- end = TickCount();
- } else
- failed = true;
- DisposeHandle((Handle) desc);
- } else
- failed = true;
- DisposeGWorld(gworld);
- } else
- failed = true;
- SetGWorld(saveport, savegdevice);
-
- if ( animCur )
- ReleaseAnimatedCursors();
-
- if ( failed ) {
- WriteStr("\p - estimated decompression speed:\r");
- WriteStr("\p - test failed\r");
- } else {
- WriteStr("\p - estimated decompression speed:\r");
- WriteStr("\p 640x480 32 bit RGB = ");
- NumToString((long) (((end - begin)*1000)/600), str);
- WriteStr(str);
- WriteStr("\p milliseconds\r");
- }
- }
-
- void ReportDecompressorSpeed(OSType type)
- {
- OSErr err;
- Str255 str;
- PicHandle tempPicture;
- long begin, end, times;
- Boolean failed;
- GWorldPtr gworld;
- CGrafPtr saveport;
- GDHandle savegdevice;
- Rect myRect = {0, 0, 480, 640};
- Boolean animCur;
-
- // Initialize.
- gworld = nil;
-
- if ( gPicture == nil )
- return;
-
- animCur = InitAnimatedCursors(beachBall, 0);
-
- if ( animCur )
- SpinCursor();
-
- failed = false;
- GetGWorld(&saveport, &savegdevice);
- err = NewGWorld(&gworld, 32, &myRect, nil, nil, 0);
- if ( err == noErr ) {
- PixMapHandle pmap;
- ImageDescriptionHandle desc;
- long size;
- Ptr data;
-
- if ( animCur )
- SpinCursor();
- SetGWorld(gworld, nil);
- LockPixels(GetGWorldPixMap(gworld));
- pmap = GetGWorldPixMap(gworld);
- EraseRect(&myRect);
- DrawPicture(gPicture, &myRect);
- desc = (ImageDescriptionHandle) NewHandle(4);
- if ( desc != nil ) {
- err = GetMaxCompressionSize(pmap, &myRect, 32, codecHighQuality, type, anyCodec, &size);
- if ( err == noErr ) {
- data = NewPtr(size);
- if ( data != nil ) {
- err = CompressImage(pmap, &myRect, codecHighQuality, type, desc, data);
- if ( err == noErr ) {
- begin = TickCount();
- for ( times = 10; times > 0; times-- ) {
- if ( animCur )
- SpinCursor();
- err = DecompressImage(data, desc, pmap, &myRect, &myRect, srcCopy, nil);
- if ( err != nil )
- failed = true;
- }
- end = TickCount();
- } else
- failed = true;
- DisposePtr(data);
- } else
- failed = true;
- } else
- failed = true;
- DisposeHandle((Handle) desc);
- } else
- failed = true;
- DisposeGWorld(gworld);
- } else
- failed = true;
- SetGWorld(saveport, savegdevice);
-
- if ( animCur )
- ReleaseAnimatedCursors();
-
- if ( failed ) {
- WriteStr("\p - estimated compression speed:\r");
- WriteStr("\p - test failed\r");
- } else {
- WriteStr("\p - estimated compression speed:\r");
- WriteStr("\p 640x480 32 bit RGB = ");
- NumToString((long) (((end - begin)*1000)/600), str);
- WriteStr(str);
- WriteStr("\p milliseconds\r");
- }
- }